package com.chris.libs.base.x.mvpp.viewholder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;

/**
 * @author Chris Chan
 * on 2019/7/5 15:24
 * use for:
 */
public abstract class BaseViewHolder {
    protected View view;

    public BaseViewHolder() {
    }

    public BaseViewHolder(View view) {
        this.view = view;
        ButterKnife.bind(this, view);
    }

    public BaseViewHolder(Context context) {
        this(context, null);
    }

    public BaseViewHolder(Context context, ViewGroup root) {
        if (null == root) {
            this.view = LayoutInflater.from(context).inflate(getLayoutId(), null);
        } else {
            this.view = LayoutInflater.from(context).inflate(getLayoutId(), root, attachToRoot());
        }
        ButterKnife.bind(this, view);
    }

    public void bind(View view) {
        this.view = view;
        ButterKnife.bind(this, view);
    }

    protected int getLayoutId() {
        return 0;
    }

    protected boolean attachToRoot() {
        return true;
    }

    public View getView() {
        return view;
    }
}
